// AESLib.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "ObjectFactory.h"
#include <crtdbg.h>

// prototypes
void newBuffer(byte** out, size_t size);
void clearBuffer(byte *out, size_t size);

int _tmain(int argc, _TCHAR* argv[])
{
	int result = E_SUCCESS;

	// manifest manages the engines
	KeyManifest km;
	
	// get a cipher engine instance 
	IAESEngine* engine		= NULL;
	
	if ( E_SUCCESS == (result = km.getEngine(&engine)))
	{

		/*** specify a key to use 
		 */
		IAESKey*	keyAlias	= NULL;
		result = km.getKey(KEY_LABEL_A, &keyAlias);



		// setup known test data
		byte*	in			= (byte*) _plaintext;


		// allocate an output buffer
		byte*	out			= NULL;
		newBuffer(&out, KEY_128 * AES_NUM_WORDS_IN_BLOCK);

		_ASSERT(out);


		/*** call for encryption 
		 */
		engine->Encrypt(keyAlias, in, out);
	}

	return 0;
}



void clearBuffer(byte *out, size_t size)
{
	if (out){
		memset (out, '\0', size);
	}
}

void newBuffer(byte** out, size_t size)
{
	byte *buffer = new byte[size];
	
	if (buffer && out){
		clearBuffer(buffer, size);

		*out = buffer;
	}
	else {
		perror ("newBuffer:: no memory error");
	}

	return;
}
